package content

import (
	"context"
	"errors"
	"github.com/gogf/gf/v2/frame/g"
	v1 "video-api/api/v1"
	"video-api/internal/model/out"
	"video-api/internal/service"
)

type contentController struct{}

var ContentsHandle = new(contentController)

func (s *contentController) GetContentList(ctx context.Context, req *v1.BannerListReq) ([]*out.Banner, error) {
	g.Log().Info(ctx, "contentController-GetGoodsList param ", g.Map{"req": req})
	if req.Version == "" {
		return nil, errors.New("产品版本编号为空")
	}
	//获取轮播图
	bannerList, err := service.ContentService().GetBannerList(ctx, &req.BannerList)
	if err != nil {
		g.Log().Error(ctx, "GetGoodsList-GetGoodsList err: "+err.Error())
		return nil, err
	}
	return bannerList, nil
}

func (s *contentController) GetTagsList(ctx context.Context, req *v1.TagReq) ([]*out.Tags, error) {
	g.Log().Info(ctx, "contentController-GetTagsList param ", g.Map{"req": req})
	//获取轮播图
	tagList, err := service.ContentService().GetTagsList(ctx, &req.TagList)
	if err != nil {
		g.Log().Error(ctx, "GetTagsList-GetTagsList err: "+err.Error())
		return nil, err
	}
	return tagList, nil
}

func (s *contentController) GetCategoriesList(ctx context.Context, req *v1.CategoriesReq) ([]*out.Categories, error) {
	g.Log().Info(ctx, "contentController-GetCategoriesList param ", g.Map{"req": req})
	//获取轮播图
	tagList, err := service.ContentService().GetCategoriesList(ctx, &req.CategoriesList)
	if err != nil {
		g.Log().Error(ctx, "GetCategoriesList-GetCategoriesList err: "+err.Error())
		return nil, err
	}
	return tagList, nil
}
